/**
 * RuleFactorValue 规则因子值对象
 */

const MATCHING_TYPE = {
  equal: 'equal',
  notEqual: 'notEqual',
  domain: 'domain',
  dateDomain: 'dateDomain',
  startWith: 'startWith',
  endWith: 'endWith',
  strContains: 'strContains',
  isNotNull: 'isNotNull',
  isNull: 'isNull',
  bizJoinCFG: 'bizJoinCFG',
  bizInCfg: 'bizInCfg',
  cfgInBiz: 'cfgInBiz',
  containAndDomain: 'containAndDomain'
}

const VALUE_TYPE = {
  single: 'single', // 单选
  multiple: 'multiple' // 多选
}

const VALUE_TYPE_BY_MATCHING_TYPE = {
  [MATCHING_TYPE.equal]: VALUE_TYPE.single,
  [MATCHING_TYPE.notEqual]: VALUE_TYPE.single,
  [MATCHING_TYPE.domain]: VALUE_TYPE.single,
  [MATCHING_TYPE.dateDomain]: VALUE_TYPE.single,
  [MATCHING_TYPE.startWith]: VALUE_TYPE.multiple,
  [MATCHING_TYPE.endWith]: VALUE_TYPE.multiple,
  [MATCHING_TYPE.strContains]: VALUE_TYPE.multiple,
  [MATCHING_TYPE.isNotNull]: VALUE_TYPE.single,
  [MATCHING_TYPE.isNull]: VALUE_TYPE.single,
  [MATCHING_TYPE.bizJoinCFG]: VALUE_TYPE.multiple,
  [MATCHING_TYPE.bizInCfg]: VALUE_TYPE.multiple,
  [MATCHING_TYPE.cfgInBiz]: VALUE_TYPE.multiple,
  [MATCHING_TYPE.containAndDomain]: VALUE_TYPE.single
}

const matchingTypeLabel = {
  [MATCHING_TYPE.equal]: '等于',
  [MATCHING_TYPE.notEqual]: '不等于',
  [MATCHING_TYPE.domain]: '属于数值区间',
  [MATCHING_TYPE.dateDomain]: '属于时间区间',
  [MATCHING_TYPE.startWith]: '以什么开头',
  [MATCHING_TYPE.endWith]: '以什么结尾',
  [MATCHING_TYPE.strContains]: '包含字符串',
  [MATCHING_TYPE.isNotNull]: '有值',
  [MATCHING_TYPE.isNull]: '没有值',
  [MATCHING_TYPE.bizJoinCFG]: '有交集',
  [MATCHING_TYPE.bizInCfg]: '包含全部规则',
  [MATCHING_TYPE.cfgInBiz]: '全部被规则包含',
  [MATCHING_TYPE.containAndDomain]: '包含且满足区间'
}

class RuleFactorValue {
  // 因子值代码
  code

  // 因子值
  data

  // 因子值默认匹配规则
  matchingRule

  // 因子值标签，用于显示
  label

  // 因子值描述信息，用于说明因子值用途
  desc

  constructor ({ code, data, matchingRule = MATCHING_TYPE.equal, label, desc } = {}) {
    this.code = code
    this.data = data
    this.matchingRule = matchingRule
    this.label = label
    this.desc = desc
  }
}
export default RuleFactorValue
export { MATCHING_TYPE, VALUE_TYPE_BY_MATCHING_TYPE, VALUE_TYPE, matchingTypeLabel }
